<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    .shenren{display: none}
</style>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">


        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>公文类型</label>
                        <div class="layui-input-block">
                            <div id="wentype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>拟稿日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" id="dt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>发文字号</label>
                        <div class="layui-input-block">
                            <div id="wenzi"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>公文编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>公文秘级</label>
                        <div class="layui-input-block">
                            <div id="wenlevel"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>紧急程度</label>
                        <div class="layui-input-block">
                            <div id="wenjin"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="title" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">主题词</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhuti" id="zhuti" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>发文单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="fadept" id="fadept" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>主送单位</label>
                        <div class="layui-input-block ">
                            <input type="text" name="zhudept" id="zhudept" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">抄送单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="chaodept" id="chaodept" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">摘要</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>


    $("#commentForm").validate({
        rules: {
            dt: {required: true},
            number: {required: true},
            title: {required: true},
            fadept: {required: true},
            zhudept: {required: true},
        },
        messages:{
            dt: {required: "请选择"},
            number: {required: "请输入"},
            title: {required: "请输入"},
            fadept: {required: "请输入"},
            zhudept: {required: "请输入"},
        }
    });


    var jietype;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_wen_ban}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }

                xmselect_dan('wentype', res.data.wentype, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#wentype").find('xm-select').removeClass('error');
                    }else{
                        $("#wentype").find('xm-select').addClass('error');
                    }
                });

                xmselect_dan('wenzi', res.data.wenzi, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#number").val(res.arr[0].name+"【"+data.year+"】  号");
                        $("#commentForm").valid();
                        $("#wenzi").find('xm-select').removeClass('error');
                    }else{
                        $("#number").val('');
                        $("#commentForm").valid();
                        $("#wenzi").find('xm-select').addClass('error');
                    }
                });

                xmselect_dan('wenlevel', res.data.wenlevel, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#wenlevel").find('xm-select').removeClass('error');
                    }else{
                        $("#wenlevel").find('xm-select').addClass('error');
                    }
                });

                xmselect_dan('wenjin', res.data.wenjin, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#wenjin").find('xm-select').removeClass('error');
                    }else{
                        $("#wenjin").find('xm-select').addClass('error');
                    }
                });



                public_upload_file_load('upload_files');
                render_date();
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');

            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                if(!data.field.wentype){
                    $("#wentype").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#wentype").find('xm-select').removeClass('error');
                }

                if(!data.field.wenzi){
                    $("#wenzi").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#wenzi").find('xm-select').removeClass('error');
                }

                if(!data.field.wenlevel){
                    $("#wenlevel").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#wenlevel").find('xm-select').removeClass('error');
                }

                if(!data.field.wenjin){
                    $("#wenjin").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#wenjin").find('xm-select').removeClass('error');
                }




                if(!validRes){return false;}

            }




            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_wen_ban, ask_flowdata_edit_wen_ban, $(this).attr('but'));

            return false;
        });

    });


</script>
</body>
</html>
